﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;

using Wxits.Data;
using Wxits.Helper;


public partial class Admin_ChildUsersList : BasePage_Grid
{
    private string _id = string.Empty;


    private int _PageSize
	{
		set { ViewState["PageSize"] = value; }
		get
		{
			return Convert.ToInt32(ViewState["PageSize"]);
		}
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
            DataCheck.CheckAuthority();

            _PageSize = 10;
			ShowData(0, _PageSize);			
		}
	}

	private void ShowData(long PageIndex, long PageSize)
	{
        string Id = Common.RequestValue("ID");
        if (string.IsNullOrEmpty(Id))
        {
            ShowMSG("错误用户参数");
            return;
        }
        if (!HelperDataCheck.IsInt32(Id))
        {
            ShowMSG("错误用户参数");
            return;
        }

        string strSQL = @"
					SELECT a.*,b.SurplusCash,b.SurplusCoin
						, (select NickName from Users where UserId = a.ParentUserId) as ParentUserName
						, (select GradeName from Mall_Grades  where GradeId = b.Grade) as GradeName
						,'StatusTxt' = 	
						CASE 
							WHEN status = 0 THEN N'禁用' 
							ELSE N'启用'
						END
					FROM  Users a  left join Mall_Users_Asset b on b.UserId = a.UserId 
					WHERE a.UserId IN (SELECT UserId FROM F_childUserIds(" + Id + ",10)) ";

        strSQL += " ORDER BY a.UserId";

        DataTable dt = DBAccess.ExecuteDataTable(strSQL);

        BindGrid(gvData, Navigator, PageIndex, PageSize, dt);
	}

	protected void Navigator_PageChanged(object sender, QHH.Web.UI.EventArg.NavigatorEventArgs e)
	{
		_PageSize = (int)e.PageSize;
		ShowData(e.NewPageIndex, _PageSize);
	}

	protected void Search_Click(object sender, EventArgs e)
	{
		ShowData(0, _PageSize);
	}
    protected string FilterStr(string Str)
    {
        return StringHelper.FilterAll(Str);
    }
}
